(function() {

	var app;

	/**
	 * [init 初始化vue]
	 * @param  {[type]} globalVue    [全局组件]
	 * @param  {[type]} componentMap [当前组件]
	 * @param  {[type]} pageMap      [路由页面]
	 */
	Vue.init = function(opts) {

		opts.global = {
			'cc-query-input': './component/input/query-input.vue',
			'cc-input': './component/input/input.vue',
			'cc-input-box-fix': './component/input/input-box-fix.vue',
			'cc-input-box-grid': './component/input/input-box-grid.vue',
			'cc-query': './component/input/query-input-group.vue',
			'cc-page': './component/content/page-init.vue',
			'cc-tag-group': './component/content/tag-group.vue',
			'cc-button': './component/system/button/button.vue',
			'cc-button-link': './component/system/button/button-link.vue',
			'cc-tree': './component/element/tree.vue',
			'cc-tag': './component/element/tag.vue',
			'cc-pagin': './component/element/pagin.vue',
			'cc-button-group': './component/element/button-group.vue',
			'cc-dialog-edit': './component/element/dialog-edit/dialog-edit-s1.vue',
			'cc-dialog': './component/element/dialog.vue',
			'cc-packet-dialog': './component/service/packet-dialog.vue',
			'cc-table': './component/element/table.vue',
			'cc-table-column': './component/element/table-column.vue',
			'cc-select-single': './component/input/select-single.vue',
			'cc-select-multi': './component/input/select-multi.vue',
			'cc-select-level': './component/input/select-level.vue',
			'cc-auth': './component/element/auth.vue',

		};

		var globalVue = opts.global || {};
		var componentMap = opts.component || {};
		var pageMap = opts.route || {};

		console.log("init vue");
		Vue.use(httpVueLoader);

		for(var key in globalVue) {
			var componentSrc = globalVue[key];
			Vue.component(key, httpVueLoader(componentSrc));
		}


		var components = {};
		for(var key in componentMap) {
			var componentSrc = componentMap[key];
			components[key] = httpVueLoader(componentSrc);
		}

		var routes = [];
		for(var key in pageMap) {
			var pageSrc = pageMap[key];
			var route = {};
			route.path = key;
			route.component = httpVueLoader(pageSrc);
			routes.push(route);
		}

		opts.global = null;
		opts.component = null;
		opts.route = null;
		opts.el = '#root';
		opts.components = components;
		if(opts.router == null) {
			opts.router = new VueRouter({
				routes : routes
			});
		}
		opts.beforeCreate = function() {
			window.UI.initVue(this);
		};

		// space boot 不需要支持ie11
		const IE11RouterFix = {
			methods: {
				hashChangeHandler: function() { this.$router.push(window.location.hash.substring(1, window.location.hash.length)); },
				isIE11: function() { return !!window.MSInputMethodContext && !!document.documentMode; }
			},
			mounted: function() { if ( this.isIE11() ) { window.addEventListener('hashchange', this.hashChangeHandler); } },
			destroyed: function() { if ( this.isIE11() ) { window.removeEventListener('hashchange', this.hashChangeHandler); } }
		};
		opts.mixins = [IE11RouterFix];
		
		app = new Vue(opts);
		return app;
	};

}());